package com.kgc.sportscircle.controller;

import com.kgc.sportscircle.pojo.Mallproduct;
import com.kgc.sportscircle.service.MallproductService;
import com.kgc.sportscircle.utils.Page;
import com.kgc.sportscircle.vo.MallproductParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 描述： 控制器
* @author 杨海文
* @date 2019/07/22
*/
@RestController
@RequestMapping("/mallproduct")
public class MallproductController{
	@Reference(version ="1.11")
	private MallproductService mallproductService;

 	@RequestMapping("/findById.json")
    public Mallproduct findById(Integer id){
        return mallproductService.findById(id);
    }

    /**
     * 描述：获取所有的Mallproduct对象
     */
    @RequestMapping("/findAll.json")
    public List<Mallproduct> findAll(){
        List<Mallproduct> result = null;
        try {
            result = mallproductService.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：新增保存Mallproduct对象
     */
    @RequestMapping("/save.json")
    public Map save(Mallproduct mallproduct){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存失败");
        try {
            if(mallproductService.save(mallproduct)>0){
                result.put("flag",true);
                result.put("msg","保存成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：根据主键删除对象
     * @param id
     */
    @RequestMapping("/delete.json")
    public Map delete(Integer id){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存失败");
        try {
            if(mallproductService.delete(id)>0){
                result.put("flag",true);
                result.put("msg","保存成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：更新对象
     */
    @RequestMapping("/update.json")
    public Map update(Mallproduct mallproduct){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","更新失败");
        try {
            if( mallproductService.update(mallproduct)>0){
                result.put("flag",true);
                result.put("msg","更新成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;

    }

    /**
     * 根据不确定的条件，动态查询
     */
    @RequestMapping("/query.json")
    public List<Mallproduct> query(MallproductParam param){
        List<Mallproduct> result = null;
        try {
            result = mallproductService.query(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 根据不确定的条件，动态分页查询
     */
    @RequestMapping("/queryByPage.json")
    public Page queryByPage(Integer categoryLevel2Id){
        MallproductParam param = new MallproductParam();
        Page result = null;
        try {
            result = mallproductService.queryByPage(param);
            System.out.println(result.getTotalCount());
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }



    /**
     * 根据推荐表查询商品
     */
    @RequestMapping("/selectAllProductByRecommend.json")
    public List<Mallproduct> selectAllProductByrecommend() {
        return mallproductService.selectAllProductByrecommend();
    }


    /**
     * 随机查询
     * @return
     */
    @RequestMapping("/selectAllProductRandom.json")
    public List<Mallproduct> selectAllProductRandom() {
        return mallproductService.selectAllProductRandom();
    }


    /**
     * 查询最新产品
     * @return
     */
    @RequestMapping("/selectNewProduct.json")
    public List<Mallproduct> selectNewProduct() {
        return mallproductService.selectNewProduct();
    }


    /**
     * 根据二级分类查询商品
     */
    @RequestMapping("/selectProductByCategoryLevel2Id.json")
    public List<Mallproduct> selectProductByCategoryLevel2Id(Integer categoryLevel2Id) {
        return mallproductService.selectProductByCategoryLevel2Id(categoryLevel2Id);
    }
 }
